package 链表;

import java.util.HashSet;
import java.util.Set;

public class getIntersectionNode {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        Set<ListNode> set=new HashSet<>();
        ListNode p=headA;
        while (p!=null){
            set.add(p);
            p=p.next;
        }
        ListNode q=headB;
        while (q!=null){
            if(set.contains(q)){
                return q;
            }
        }

        return null;
    }
}
